chrome.runtime.onInstalled.addListener(function() {
	console.log("Installed.");
	// Replace all rules ...
	chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page's URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: '1mobile' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });


  	//chrome.storage.local.set({'aa': 'abc'}, function(){
  		//message('设置已保存');
  	//});
});

chrome.runtime.onSuspend.addListener(function() {
  // 做一些简单的清理任务。
});

chrome.runtime.onStartup.addListener(function() {
	console.log('Starting browser... updating icon.');
});



chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "来自内容脚本：" + sender.tab.url :
                "来自扩展程序");
    if (request.greeting == "您好")
      sendResponse({farewell: "再见"});
});


//监听webrequest

chrome.webRequest.onBeforeRequest.addListener(
  function(info) {
    console.log("Cat intercepted: " + info.url);
    // Redirect the lolcal request to a random loldog URL.
    //return {redirectUrl:'http://www.baidu.com/'};
	//chrome.tabs.create({url:'http://www.baidu.com/'},function(tab){
					
	//});
	alert('bbbbbb');
	//chrome.tabs.executeScript(null,{file:"wish.html"});
	
  },
  // filters
  {
    urls: ["http://www.1mobile.com/d.php*"]
  },
  // extraInfoSpec
  ["blocking"]);



//服务器做统计
function stat_log(cycle){
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "http://local.cms.com/Chrome_App_1Mobile/test.php?type=" + cycle, true);
	xhr.onreadystatechange = function(){
		if (xhr.readyState == 4) {
		//请求成功做处理
		}
	}
	xhr.send();
}